home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / Display.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  7.7 KB  |  303 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Display.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>      1/5/94    EZ        fix compilation error when txtnMultiFrames is set
  13.          <2>      1/4/94    EZ        clean up
  14.          <1>      1/4/94    EZ        first checked in
  15.  
  16. */
  17.  
  18. #ifndef _Display_
  19. #define _Display_
  20.  
  21.  
  22.  
  23. #ifndef _ToolBoxDump_
  24. #include "ToolBoxDump.h"
  25. #endif
  26.  
  27. #ifndef _TextensionCommon_
  28. #include "TextensionCommon.h"
  29. #endif
  30.  
  31. #ifndef _RunObject_
  32. #include "RunObject.h"
  33. #endif
  34.  
  35. #ifdef txtnRulers
  36. #ifndef _RulersRanges_
  37. #include "RulersRanges.h"
  38. #endif
  39. #endif
  40.  
  41. #ifndef _Frames_
  42. #include "Frames.h"
  43. #endif
  44.  
  45. #ifndef _StyledText_
  46. #include "StyledText.h"
  47. #endif
  48.  
  49. #ifndef _Formatter_
  50. #include "Formatter.h"
  51. #endif
  52.  
  53. #ifndef _FrameFormatter_
  54. #include "FrameFormatter.h"
  55. #endif
  56.  
  57. #ifndef _Line_
  58. #include "Line.h"
  59. #endif
  60. //***************************************************************************************************
  61.  
  62. #ifdef __SC__
  63. class __machdl CSelection;
  64. class __machdl CTextension;
  65. #else
  66. class CSelection;
  67. class CTextension;
  68. #endif
  69.  
  70. struct TDrawEnv {
  71.     TDrawEnv(char nesting = 0) : savedTextEnv(nesting) {allowNesting = nesting;}
  72.     
  73.     char allowNesting;
  74.     TTextEnv    savedTextEnv;
  75.     RgnHandle userClip;
  76. };
  77.  
  78. struct TEditInfo {
  79.     inline TEditInfo() {checkUpdateRgn = true;}
  80.     
  81.     Boolean checkUpdateRgn; //input to BeginEdit
  82.     Boolean editSuccess; //input to EndEdit
  83.     
  84.     #ifdef txtnMultiFrames
  85.     long oldCountFrames; //from BeginEdit to EndEdit
  86.     #else
  87.     long oldLinesHite;
  88.     #endif
  89.     
  90.     TDrawEnv savedDrawEnv; //from BeginEdit to EndEdit
  91.     
  92.     char oldSelState;
  93. };
  94.  
  95. //***************************************************************************************************
  96.  
  97.  
  98. //const for visOption to "IsSelectionVisible"
  99. const short kCenterSelection = 1;
  100. const short kNearestSelection = 2;
  101.  
  102. //const for drawing routines"
  103. typedef ushort TDrawFlags;
  104.  
  105. const TDrawFlags kNoDrawFlags = 0;
  106. const TDrawFlags kEraseBeforeDraw = 1 << 0;
  107. const TDrawFlags kFirstLineOffScreen = 1 << 1; //internal
  108. const TDrawFlags kDrawAllOffScreen = 1 << 2;
  109.  
  110. //***************************************************************************************************
  111.  
  112. void InitDisplay();
  113.  
  114. void EndDisplay();
  115.  
  116. //***************************************************************************************************
  117.  
  118. struct TDisplayHandlers {
  119.     CSelection* selectionHandler;
  120.     CStyledText* styledTextHandler;
  121.     CFormatter* formatHandler;
  122.     CFrames* framesHandler;
  123.     
  124.     #ifdef txtnRulers
  125.     CRulersRanges* rulersRanges;
  126.     #endif
  127. };
  128. //***************************************************************************************************
  129.  
  130. class CTextensionDisplay : public HandleObject {
  131.     friend class CTextension;
  132.     friend class CSelection;
  133.     
  134.     public :
  135. //--------
  136.     CTextensionDisplay();
  137.     
  138.     void ITextensionDisplay();
  139.     
  140.     void SetHandlers(TDisplayHandlers* handlers, TSize sizeInfo);
  141.     
  142.     virtual void Free();
  143.     
  144.     virtual void FreeData();
  145.     
  146.     #ifdef txtnNever
  147.     virtual CTextensionDisplay* CreateEmptyClone();
  148.     #endif
  149.     
  150.     inline CFrames* GetFramesHandler() {return fFrames;}
  151.     
  152.     void HideDrawPen(); //like HidePen
  153.     void ShowDrawPen(); //like ShowPen
  154.     
  155.     void GetViewRect(Rect* theRect) const;
  156.     void SetViewRect(const Rect* theRect);
  157.     
  158.     virtual void Draw(const Rect *updateRect, TDrawFlags drawFlags = kEraseBeforeDraw);
  159.     //if updateRect is nil ==> draw all
  160.     
  161.     void DrawChars(long firstOffset, long lastOffset, TDrawFlags drawFlags = kEraseBeforeDraw);
  162.     
  163.     void InvalidDraw();
  164.     
  165.     inline short GetLastEditAction() {return fLastEditAction;}
  166.     //after any edit operation, the returned value is a combination of bits same as returned from DisplayChanged
  167.     
  168.     inline void SetLastEditAction(short action) {fLastEditAction |= action;}
  169.     
  170.     void Scroll(const LongPoint* scrollVals);
  171.     void GetScrolledValues(LongPoint* scrolledVals);
  172.  
  173.     void Activate(Boolean activ, Boolean turnSelOn =true);
  174.  
  175.     Boolean IsSelectionVisible(const Rect* visRect, LongPoint* scrollVals
  176.                                                         , short visOption =kCenterSelection, Boolean visSelEnd = true);
  177.  
  178.     void SetDirection(char newDirection); // does NOT have a draw effect
  179.     inline char GetDirection() const {return fDirection;}
  180.  
  181.     #ifdef txtnScal
  182.     void SetScale(Point numer, Point denom); // does NOT have a draw effect
  183.     inline void GetScale(Point* numer, Point* denom) {fFrames->GetScale(numer, denom);}
  184.     #endif
  185.     
  186.     void LineCharsLocs(long lineNo, TOffsetRange charRange
  187.                                         , TCharLocs* charLocsArr, Boolean lineBounds, char caretDir = kRunDir);
  188.     
  189.     Boolean Visible2BackOrder(TOffset* charOffset, char runDir);
  190.     
  191.     CRunObject* Point2Char(Point thePt, TOffsetRange* charRange, Boolean* outside);
  192.     //•returns a val < 0 in charRange->rangeStart if the point is not in any frame
  193.     
  194.     long Point2Line(Point* thePt, Boolean* outside, Boolean* vOverflow, TOffsetRange* lineRange = nil) const;
  195.     //•see comment on Point2Line in Frames.h
  196.         
  197.     void Char2Point(TOffset theChar, long* top, long* trailEdge=nil, short* hite =nil);
  198.     // top and trailEdge are in abs coord
  199.     //hite in output (if not nil) is set to the line hite of the line containing the char
  200.     
  201.     Point Char2Point(TOffset theChar, short* hite =nil);
  202.     
  203.     #ifdef txtnDebug
  204.     inline char DrawEnvLevel() {return fDrawEnvLevel;}
  205.     #endif
  206.     
  207.     protected :
  208. //-----------
  209.     CSelection* fSelection;
  210.     CFrames* fFrames;
  211.     CStyledText* fStyledText;
  212.     CFormatter* fFormatter;
  213.     CFrameFormatter* fFrameFormatter;
  214.     
  215.     char    fDirection;
  216. //------------------------------------------
  217.     
  218.     #ifdef txtnNever
  219.     //bits modif notify is false by default
  220.     inline void EnableBitsModifNotify() {++fBitsModifLevel;}
  221.     inline void DisableBitsModifNotify() {--fBitsModifLevel;}
  222.  
  223.     virtual void PreRectBitsModif(const Rect* theRect);
  224.     #endif
  225.     
  226.     virtual void Focus(RgnHandle* savedClip);
  227.     virtual void UnFocus(RgnHandle savedClip);
  228.     
  229.  
  230.     virtual void BeginEdit(TEditInfo* editInfo);
  231.     virtual void EndEdit(const TEditInfo* editInfo, long firstFormatLine, long lastFormatLine
  232.                                             , TOffset* selOffset=nil);
  233.     
  234.     private:
  235. //--------
  236.     CLine* fLine;
  237.     
  238.     char fDrawEnvLevel;
  239.     
  240.     #ifdef txtnNever
  241.     char fBitsModifLevel;
  242.     #endif
  243.     
  244.     char fHasViewRect;
  245.     Rect fViewRect;
  246.  
  247. static short fLastEditAction;
  248. /*declared static when foot notes have been implemented. In this case it's important to remember
  249. the edit action in the master textension even if the context has been changed after the edit 
  250. operation (insert foot note for instance) */
  251.  
  252. static char fDrawVisLevel;
  253. /*
  254. declared global when foot notes have been implemented, in this case user may want to hide draw
  255. across calls which may change the context (and thus the Display)
  256. */
  257.  
  258. //------------------------------------------
  259.         
  260.     void CalcLine(long lineNo);
  261.     
  262.     inline Boolean IsDrawHidden() {return fDrawVisLevel < 0;}
  263.     
  264.     void SetDrawEnv(TDrawEnv* savedDrawEnv, Boolean checkUpdateRgn =false);
  265.     
  266.     void RestoreDrawEnv(const TDrawEnv& savedDrawEnv);
  267.     
  268.     #ifdef txtnMultiFrames
  269.     void GetViewFrames(CSectFrames* visFrames) const;
  270.     #endif
  271.     
  272.     void DrawLineGroup(const TSectLines* group2Draw, RgnHandle drawClip
  273.                                         , TDrawFlags drawFlags);
  274.  
  275.     Boolean DrawFrameText(long frameNo, TDrawFlags drawFlags, const Rect* rect2Draw =nil);
  276.  
  277.     Boolean ScrollRect(const Rect* rect2Scroll, long hPix, long vPix, RgnHandle invalidRgn
  278.                                     , Boolean move = false);
  279.     
  280.     #ifdef txtnMultiFrames
  281.     void UpdateScrolledArea(RgnHandle invalidRgn, const T1FrameEditInfo* frameEditInfo);
  282.  
  283.     void FrameEndEdit(const T1FrameEditInfo* editInfo, long startPix, long hite=-1);
  284.  
  285.     void EraseFrameBottom(long frameNo);
  286.  
  287.     void ScrollFrame(const T1FrameEditInfo* frameEditInfo);
  288.     void UpdateOverflowLines(const T1FrameEditInfo* frameEditInfo);
  289.  
  290.     #else
  291.     void UpdateScrolledArea(RgnHandle invalidRgn);
  292.  
  293.     void FrameEndEdit(const TEditInfo* editInfo, long startPix, long hite=-1);    
  294.     #endif
  295.     
  296.     
  297.     void CheckScroll(Boolean doUpdate = true);        
  298. };
  299. //***************************************************************************************************
  300.  
  301.  
  302. #endif
  303.